/**
 * 
 */
package com.qiaoan.back.controller;

import com.alibaba.fastjson.JSONObject;
import com.qiaoan.back.enums.ResultCode;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.io.Serializable;

/**
 * @author zhang_chong521
 *
 */
public class BaseController implements Serializable{

    public static Logger logger = LogManager.getLogger(BaseController.class.getName());


    /**
     *
     * @param response
     * @param code
     * @param message
     */
    public void printJson(HttpServletResponse response , ResultCode code , String message) {


        JSONObject json = new JSONObject();
        json.put("code", code.getValue());
        logger.info("**************************************************code: " + code);
        json.put("msg", message);

        // Print
        PrintWriter out;
        try {
            out = response.getWriter();
            out.print(json.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     *
     * @param response
     * @param code
     * @param json
     */
    public void printJson(HttpServletResponse response , ResultCode code ,JSONObject json ){

        //操作日志

        logger.info("**************************************************code: "+code);

        // Print
        PrintWriter out;
        try {
            out = response.getWriter();
            out.print(json.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



}
